package com.aw.qzblog.aop;

import com.aw.qzblog.annotation.AdminCheck;
import com.aw.qzblog.entity.enums.ErrorEnum;
import com.aw.qzblog.entity.vo.user.UserBaseInfo;
import com.aw.qzblog.exception.SysException;
import com.aw.qzblog.utils.CurrentUserUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AdminCheckAop {


    @Around("@annotation(adminCheck)")
    public Object testCutAround(ProceedingJoinPoint joinPoint, AdminCheck adminCheck) throws Throwable {
        UserBaseInfo currentUser = CurrentUserUtil.getCurrentUser();
        if (!adminCheck.role().equals(currentUser.getRole())) {
            throw new SysException(ErrorEnum.NO_PERMISSION);
        }
        return joinPoint;
    }


}
